package com.tkjt.pms.calc.common;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class CalcDepartChain {

	private Map<Integer, Set<DepartOwner>> calcDepartChain = new HashMap<Integer, Set<DepartOwner>>();

	public void addLevelCodes(Integer level, Set<DepartOwner> depenList) {
		Set<DepartOwner> tempMap = calcDepartChain.get(level);
		if (null == tempMap) {
			tempMap = new HashSet<DepartOwner>();
			calcDepartChain.put(level, tempMap);
		}
		if(null==depenList) {
			return;
		}
		tempMap.addAll(depenList);
	}

	public void addLevelCodes(Integer level, List<DepartOwner> depenList) {
		Set<DepartOwner> tempMap = calcDepartChain.get(level);
		if (null == tempMap) {
			tempMap = new HashSet<DepartOwner>();
			calcDepartChain.put(level, tempMap);
		}
		tempMap.addAll(depenList);
	}

	public void addOneLevelCode(Integer level, DepartOwner departOwner) {
		Set<DepartOwner> tempMap = calcDepartChain.get(level);
		if (null == tempMap) {
			tempMap = new HashSet<DepartOwner>();
			calcDepartChain.put(level, tempMap);
		}
		tempMap.add(departOwner);
	}

	public Integer getLevelSize() {
		Integer maxLevel = 0;
		Set<Integer> levels = calcDepartChain.keySet();
		for (Integer level : levels) {
			if (maxLevel < level) {
				maxLevel = level;
			}
		}
		return maxLevel;
		//return calcDepartChain.size();
	}

	public Set<DepartOwner> getLevelCodes(Integer level) {
		Set<DepartOwner> tempSet = calcDepartChain.get(level);
		if (null == tempSet) {
			return new HashSet<DepartOwner>();
		}
		return tempSet;
	}

}
